package com.aerors.DataProcess;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * shapefile转geojson
 * @author wx
 *
 */
public class Shp2GeoJSON {
	private static final String transferTemplate = "ogr2ogr -f \"GeoJSON\" %s %s";
	private static final String baseDir = "C:\\data\\shapes\\intersection";
	private static final String outDir = "C:\\data\\geojson\\intersection";
	
	public static void main(String[] args) {
		Shp2GeoJSON app = new Shp2GeoJSON();
		List<String> list = app.transfer2GeoJSON(baseDir);
		if(list.size() > 0) {
			for(String command : list) {
				CommandExector.execCommand(command);
			}
		}
	}
	
	public List<String> transfer2GeoJSON(String dir) {
		List<String> list = new ArrayList<>();
		File folder = new File(dir);
		for(File f :folder.listFiles()) {
			String fName = f.getName();
			if(fName.endsWith(".shp")) {
				String outName = fName.replace(".shp", ".json");
				String outPath = outDir + File.separator + outName;
				list.add(String.format(transferTemplate,outPath, f.getAbsolutePath()));
			}
		}
		
//		System.out.println(list);
		return list;
	}
}
